/**
 * 医嘱项管理初始化
 */
 var CdcOrdgroupList = {
    id: "CdcOrdListTable",	//表格id
    seItems: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdcOrdgroupList.initColumn = function () {
    return [
        {field: 'selectItem', checkbox: true},
        {title: '代码', field: 'code', align: 'center', valign: 'middle', sortable: true},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true},
        {title: '类型', field: 'busOrderType.description', align: 'center', valign: 'middle', sortable: true}
    ];
};

/**
 * 检查是否选中
 */
CdcOrdgroupList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcOrdgroupList.seItems = selected;
        return true;
    }
};
CdcOrdgroupList.save= function () {
    if(CdcOrdgroupList.check()){
        var ordIds="";
        for (var index = 0; index < CdcOrdgroupList.seItems.length; index++) {
            var seItem = CdcOrdgroupList.seItems[index];
            ordIds=ordIds+":"+seItem.id;
        }
        var ajax = new $ax(Sys.backendPath + "/cdc/cdcordgroupentry/save", function (data) {
            Sys.success("添加成功!");
            parent.layer.close(parent.layer.getFrameIndex(window.name));
            window.parent.CdcOrdgroupEntry.table.refresh();
        }, function (data) {
            Sys.error("添加失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ordGroupId",CdcOrdgroupList.ordGroupId);
        ajax.set("ordIds",ordIds);
        ajax.start();
    }
}
/**
 * 查询医嘱项列表
 */
CdcOrdgroupList.search = function () {
    var queryData = {};
    queryData['description'] = $("#description").val();
    CdcOrdgroupList.table.refresh({query: queryData});
};

$(function () {
    CdcOrdgroupList.sysDataId=window.parent.CdcOrdgroupEntry.sysDataId;
    CdcOrdgroupList.ordGroupId=window.parent.CdcOrdgroupEntry.ordGroupId;
    
    var defaultColunms = CdcOrdgroupList.initColumn();
    var table = new BSTable(CdcOrdgroupList.id, Sys.backendPath + "/cdc/cdcordmast/list", defaultColunms);
    table.setPaginationType("server");
    table.setShowRefresh(false);
    table.setShowColumns(false);
    table.setShowToggle(false);
    table.setShowExport(false);
    table.setPageSize(10);
    table.setSubHead(5);
    table.setQueryParams({ "dataId": CdcOrdgroupList.sysDataId });
    CdcOrdgroupList.table = table.init();
});
